package leetcode;


import java.util.ArrayList;
import java.util.List;

/**
 * 杨辉三角
 */
public class LeetCode118 {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result = new ArrayList();
        for (int i = 0; i < numRows; i++) {
            int[] nums = new int[i + 1];
            nums[0] = 0;
            nums[i] = i;
            for (int j = 1; j < i; j++) {
                nums[j] = result.get(i - 1).get(j - 1) + result.get(i - 1).get(j);
            }
            result.add(toList(nums));
        }
        return result;
    }

    public List<Integer> toList(int[] nums) {
        List<Integer> list = new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }
        return list;
    }
}